package com.eshop.we.service;


import com.alibaba.dubbo.config.annotation.Service;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.eshop.we.book.api.BookService;
import com.eshop.we.book.dto.BookDto;
import com.eshop.we.book.entity.Book;
import com.eshop.we.mapper.BookMapper;
import com.eshop.we.utils.DateUtil;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * <p>
 * 书籍表 服务实现类
 * </p>
 *
 * @author anonymity
 * @since 2018-07-04
 */
@Service(interfaceClass = BookService.class)
@Component
public class BookServiceImpl extends ServiceImpl<BookMapper, Book> implements BookService {


    @Override
    public Page selectBookPage(Page<BookDto> page, String name, String bookName, String startDate, String endDate) {
        Long start=null;
        Long end=null;
        try{
            start= startDate!=null? DateUtil.str2Date(startDate+" 00:00:00").getTime():null;
            end= endDate!=null?DateUtil.str2Date(endDate+" 23:59:59").getTime():null;
        }catch (Exception e){
            e.printStackTrace();
        }
        List<BookDto> list=baseMapper.selectBookPage(page,name,bookName,start,end);
        page.setRecords(list);
        return page;
    }

    @Override
    public List<Book> searchBook(Book book) {
        EntityWrapper<Book> ew = new EntityWrapper<Book>();
        ew.where("category_id={0}",book.getCategoryId()).and();
        return baseMapper.selectList(ew);
    }
}
